/**
 * IP 校验
 * @param rule
 * @param value
 * @param callback
 * @returns {boolean|*}
 */
export const ipValid = (rule, value, callback) => {
  let reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
  console.log("ipValid.value: %o",value)
  if (!!value){
    if (!reg.test(value)) {
      return callback(new Error('请输入有效的IP地址'))
    } else {
      callback()
    }
  }
  return true
}

/**
 * 端口校验
 * @param rule
 * @param value
 * @param callback
 * @returns {boolean|*}
 */
export const portValid = (rule, value, callback) => {
  let reg= /^(([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))$/
  //console.log("portValid.value: %o",value)
  if (!!value){
    if (!reg.test(value)) {
      return callback(new Error('请输入有效的端口号'))
    } else {
      callback()
    }
  }
  return true
}


/**
 * URL校验
 * @param rule
 * @param value
 * @param callback
 * @returns {boolean|*}
 */
export const httpValid = (rule, value, callback) => {
  //var reg = /^(([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))$/
/*  let reg = http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
  //console.log("portValid.value: %o",value)
  if (!!value){
    if (!reg.test(value)) {
      return callback(new Error('请输入有效的端口号'))
    } else {
      callback()
    }
  }
  return true*/
  return true;
}
